package com.day1019.snake;

import javax.swing.*;
import java.awt.*;

/**
 贪吃蛇画布
 */

public class GamePanel extends JPanel {
    /**
     *@param：g 画笔
     * 绘制方法
     */
    Snake snake = new Snake();
    static Food food = new Food();

    @Override
    public void paint(Graphics g) {
        //  画横线
        for (int i = 0; i < 41; i++) {
            g.drawLine(0,15*i,650,15*i);
        //   画竖线
        }
        for (int i = 0; i < 42; i++) {
            g.drawLine(15*i,0,15*i,660);
        }
        //  画🐍
        for (Node node : snake.getBody()) {
            //    Rect  矩形
            g.fillRect(node.getX()*15,node.getY()*15,15,15);
        }
        g.setColor(Color.red);
        g.fillRect(food.getX()*15,food.getY()*15,15,15);


    }
}
